#ifndef CBACKENDWND_H_
#define CBACKENDWND_H_

#include <QWidget>
#include <QListView>
#include "ui_BackendWnd.h"

#include "CommonType.h"
#include "COperLogManager.h"
#include "CabinetManager.h"

class QStandardItemModel;
class CCustomBoxView;

class CBackendWnd : public QWidget
{
	Q_OBJECT

public:
	explicit CBackendWnd(QWidget *parent = 0);
	~CBackendWnd();

	void LoadData();
	void UpdatePanelAdvance();
	void UpdateLockerStatus();
    void SetLevel(int32_t t);
    void SetAccount(std::string account);

protected:
	void init();
    void init_panel_layout();
	void init_panel_inquery_order();
    void init_panel_manager_card();
    void init_panel_advance();
    void init_panel_payment_manager();
    void init_panel_paid_details();

    void update_panel_layout();
    void update_panel_dashboard();
    void update_panel_manager_card();
    void update_panel_advance();
    void update_panel_payment_manager();

    QString convert_billing_unit(int32_t unit);
    void query_order();
    void query_oper();
    void query_payment();

    void store_data_to_model_dcb(const zl::DoorControlBoard& dcb, const QModelIndex& index);
    void read_data_from_model_dcb(zl::DoorControlBoard& dcb, const QModelIndex& index);

protected slots:
    void on_btnl_back_clicked();

    // 格口控制页面
    void on_btni_open_clicked();
    void on_btnw_clean_clicked();
    void on_btnd_lock_clicked();
    void on_btns_unlock_clicked();
	
    // 布局配置页面
    void on_btns_add_row_clicked();
    void on_btnd_del_row_clicked();
    void on_btni_save_layout_clicked();
    void on_btns_add_dcb_clicked();
    void on_btnd_del_dcb_clicked();
    // 开门板配置表格双击事件
    void on_tb_dcb_doubleClicked(const QModelIndex &index);

    // 管理卡页面
    void on_btns_register_card_clicked();
    void on_btni_set_root_card_clicked();
    void on_btnw_set_normal_card_clicked();
    void on_btnw_lock_card_clicked();
    void on_btns_unlock_card_clicked();
    void on_btnd_del_card_clicked();

    // 记录查询页面
    void on_btns_query_record_clicked();

    // 高级配置页面
    void on_btni_save_config_clicked();
    void on_btnd_exit_clicked();
    void on_btnp_system_settings_clicked();

    // 付费方案配置界面
    void on_btns_add_payment_clicked();
    void on_btnw_modify_payment_clicked();
    void on_btnd_delete_payment_clicked();
    void on_btni_save_payment_conf_clicked();

    void event_navi_btn_clicked(int index);
    void event_locker_cell_clicked(int32_t lockerno);
    void record_type_changed(int index);

signals:
	void backToHome();
	void exitApp();
	void configChanged();

private:
	Ui::BackendWnd ui;

    QStandardItemModel*		model_layout_;
    QStandardItemModel*     model_dcb_;
	QStandardItemModel*		model_manager_card_;
    QStandardItemModel*		model_query_;
    QStandardItemModel*     model_payment_;

	CCustomBoxView*			wnd_layout_;
	QTimer*					timer_;

    std::string             admin_account;
};

#endif // CBACKENDWND_H_
